﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;

namespace WebApplication1
{
    public class DbHelper
    {
        #region 数据库连接字符串
        public static readonly string conString = "server= .; database = InSaleSave; uid = sa; pwd = 123456";
        #endregion

        #region 数据库数据获取
        public static DataTable GetDatatable(string sql)
        {
            //获取数据库数据
            SqlDataAdapter dataAdapter = new SqlDataAdapter(sql,conString);
            //新建数据表
            DataTable dataTable = new DataTable();
            //填充表
            dataAdapter.Fill(dataTable);
            //返回表
            return dataTable;
        }
        #endregion

        #region 删改查
        public static int AddOrDeletedOrUpdated(string sql)
        {
            SqlConnection connection = new SqlConnection(conString);

            SqlCommand sqlCommand = new SqlCommand(sql,connection);

            connection.Open();

            var qy = sqlCommand.ExecuteNonQuery();

            connection.Close();

            return qy;
        }
        
            
            

        
        #endregion
    }
}